/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package dp1.titandevelop.titano.view.sec;

import dp1.titandevelop.titano.persistent.Perfil;
import dp1.titandevelop.titano.persistent.PermisoXPerfil;
import dp1.titandevelop.titano.persistent.Usuario;
import dp1.titandevelop.titano.service.AuditoriaService;
import dp1.titandevelop.titano.service.PerfilService;
import dp1.titandevelop.titano.service.ValidacionService;
import dp1.titandevelop.titano.view.LoginT;
import java.awt.Cursor;
import java.awt.Dimension;
import java.awt.FileDialog;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.table.AbstractTableModel;

/**
 *
 * @author chrestean
 */
public class ModulosT_SEG_Audit extends javax.swing.JInternalFrame {

   

    // Fin del modelo de la tabla Permisos
    public ModulosT_SEG_Audit() {
        initComponents();
        

    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        btnBuscar = new javax.swing.JButton();

        setResizable(true);
        setTitle("Auditoria");
        setMaximumSize(new java.awt.Dimension(550, 450));
        setMinimumSize(new java.awt.Dimension(550, 450));
        setName(""); // NOI18N
        setPreferredSize(new java.awt.Dimension(550, 450));

        btnBuscar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/buscar.png"))); // NOI18N
        btnBuscar.setToolTipText("Buscar");
        btnBuscar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnBuscarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(btnBuscar)
                .addContainerGap(25, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(btnBuscar)
                .addContainerGap(26, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnBuscarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnBuscarActionPerformed
        ArrayList<String> username = new  ArrayList<String>();
        ArrayList<String> perfiles = new  ArrayList<String>();
        ArrayList<String> tablas = new  ArrayList<String>();
        ArrayList<String> acciones = new  ArrayList<String>();
        ArrayList<String> fechas = new  ArrayList<String>();
        AuditoriaService as = new AuditoriaService();
        System.out.println("Llegue hasta aqui");
        as.leerDatosAuditoria(username,perfiles,tablas,acciones,fechas);
        System.out.println("logre leer");
        try {
            
            System.out.println("Entre aqui");
            if(!username.isEmpty() &&  !perfiles.isEmpty() && !tablas.isEmpty() && !acciones.isEmpty() && !fechas.isEmpty()  ){
                String nombreArchivo = "/tmp/auditoria.pdf";
                FileDialog fd = new FileDialog(new JFrame(), "Guardar", FileDialog.SAVE);
                fd.setDirectory(".");
                fd.setFile("*.pdf");
                fd.setVisible(true);
                nombreArchivo = fd.getDirectory() + fd.getFile();
                if(fd.getFile()!=null){
                    this.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
                    reporte_auditoria report=new reporte_auditoria(fechas,username,perfiles,tablas,acciones,nombreArchivo);
                    this.setCursor(Cursor.getDefaultCursor());
                    JOptionPane.showInternalMessageDialog(this.getRootPane(),"El Reporte a sido generado satisfactoriamente","Mensaje",JOptionPane.INFORMATION_MESSAGE);
                }
            }else{
            JOptionPane.showInternalMessageDialog(this.getRootPane(),"No hay datos para ingresar al reporte", "Aviso", JOptionPane.WARNING_MESSAGE);
            }
        } catch (Exception ex) {
            JOptionPane.showInternalMessageDialog(this.getRootPane(), "El PDF se encuentra abierto y no se puede sobrescribir", "Mensaje", JOptionPane.INFORMATION_MESSAGE);
            Logger.getLogger(ModulosT_SEG_Audit.class.getName()).log(Level.SEVERE, null, ex);
        }
         
    }//GEN-LAST:event_btnBuscarActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnBuscar;
    // End of variables declaration//GEN-END:variables
}
